package com.example.day01.finger_guest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.day01.R;

public class ResultActivity extends AppCompatActivity implements View.OnClickListener {
    ImageView result_iv;
    TextView tv_1,tv_2;
    Button restartBtn;
    String jia;
    String yi;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        result_iv=findViewById(R.id.result_iv);
        tv_1=findViewById(R.id.result_tv_win1);
        tv_2=findViewById(R.id.result_tv_win2);
        restartBtn=findViewById(R.id.result_btn);
        restartBtn.setOnClickListener(this);
        Intent intent=getIntent();
        jia = intent.getStringExtra("jia");
        yi = intent.getStringExtra("yi");
        //判断输结果
        judgeResult(jia,yi);


    }

    private void judgeResult(String jia, String yi) {
        /*@des:判断猜拳游戏的函数

         */
        if (jia.equals(yi)) {//平局
            tv_1.setText("甲乙");
            tv_2.setText("甲乙平局");
            result_iv.setImageResource(R.mipmap.ok);
            return;
        }
        //判断甲赢了
        if ((jia.equals("剪刀")&&yi.equals("布"))||
                (jia.equals("石头")&&yi.equals("剪刀"))||
                (jia.equals("布")&&yi.equals("石头"))){
            tv_1.setText("甲");
            tv_2.setText("甲赢了");
            result_iv.setImageResource(R.mipmap.face_a);
            return;
        }
        //判断乙赢了
        tv_1.setText("乙");
        tv_2.setText("乙赢了");
        result_iv.setImageResource(R.mipmap.face_b);
    }

    @Override
    public void onClick(View v) {
        //再来一局
        Intent intent=new Intent();
        intent.setClass(this,GuestActivity01.class);
        startActivity(intent);
        finish();
    }
}
